/*
 * CS_DUNGEON_CARD_REWARD_EXECUTE_READY.cpp
 *
 *  Created on: 2013. 5. 21.
 *      Author: the2
 */

#include "../../Command.h"

#include "../../User.h"

#include "../../NLogic/Card.h"
#include "../../NLogic/Space.h"
#include "../../NLogic/Battle.h"
#include "../../NResource/Static.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_DUNGEON_CARD_REWARD_EXECUTE_READY(User * pUser, ::Network::Packet * pPacket)
{
/*	CS_DUNGEON_CARD_REWARD_EXCUTE_READY	0x1114
	{
	}

	SC_DUNGEON_CARD_REWARD_EXCUTE_READY	0x1115
	{
		s16		ack;
		u8		u8is_event;				//할인 이벤트 여부 0: 이벤트 아님, 1: 이벤트 중
		u8		count		(MAX : 6)	//던전 보상일 때는 (일반+젠 포함) 6장, 아이템 뽑기 일때는 (젠카드) 3장
		{
			s8		class_type;
			u8		sheet_type;
			u16		item_tid;
			u8		item_quality;
			u8		refine_step;
		}
	}*/

	PREPARE_PACKET;

	NLogic::Space * pSpace = pUser->GetSpace();
	if (NULL == pSpace)
	{
		DEBUGLOG("%s : NULL == pSpace", __FUNCTION__);
		return;
	}

	if (false == pSpace->IsDungeon())
	{
		DEBUGLOG("%s : space is not single or party dungeion", __FUNCTION__);
		return;
	}

	NLogic::Card * pCard = pUser->GetCard();
	if (NULL == pCard)
	{
		DEBUGLOG("%s : pCard is NULL!!", __FUNCTION__);
		return;
	}

	pCard->Clear();

	if (false == NResource::Static::InstancePtr()->GetDungeonReward()->DungeonRewardReady(pUser))
	{
		DEBUGLOG("%s : DungeonRewardReady False", __FUNCTION__);
		return;
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck << static_cast<int16_t>(ACK_OK);

	// 젠 카드 가격 이벤트 여부
	if (true == NResource::Static::InstancePtr()->GetEventTime()->IsDungeonRewardZenCardEvent(pUser))
		*pAck << static_cast<uint8_t>(1);
	else
		*pAck << static_cast<uint8_t>(0);

	*pAck << static_cast<uint8_t>(pCard->HasCardCount());

	// 일반 카드
	for (int i = 0; i < pCard->GetMaxCount(); i++)
	{
		NLogic::Card::Data * pData = pCard->GetNormalCardData(static_cast<NLogic::Card::CardItemType>(i));

		if (NULL == pData)
			continue;

		*pAck << static_cast<int8_t>(pData->classType);
		*pAck << static_cast<uint8_t>(pData->sheetType);
		*pAck << static_cast<uint16_t>(pData->tid);
		*pAck << static_cast<uint8_t>(pData->quality);
		*pAck << static_cast<uint8_t>(pData->refine);
		*pAck << static_cast<uint8_t>(pData->effType);
		*pAck << static_cast<uint8_t>(pData->effPos);
		*pAck << static_cast<uint16_t>(pData->effValue);
	}

	// 젠 카드
	for (int i = 0; i < pCard->GetMaxCount(); i++)
	{
		NLogic::Card::Data * pData = pCard->GetZenCardData(static_cast<NLogic::Card::CardItemType>(i));

		if (NULL == pData)
			continue;

		*pAck << static_cast<int8_t>(pData->classType);
		*pAck << static_cast<uint8_t>(pData->sheetType);
		*pAck << static_cast<uint16_t>(pData->tid);
		*pAck << static_cast<uint8_t>(pData->quality);
		*pAck << static_cast<uint8_t>(pData->refine);
		*pAck << static_cast<uint8_t>(pData->effType);
		*pAck << static_cast<uint8_t>(pData->effPos);
		*pAck << static_cast<uint16_t>(pData->effValue);
	}

	pAck->MakePacket(CMD_SC_DUNGEON_CARD_REWARD_EXECUTE_READY);
	pUser->Send(pAck);
}

} /*NCommand*/ } /*ProjectZ*/
